	// EditableTable 可编辑表格
	var EditableTable=function(selector){
		this.selector=selector;
	}
	EditableTable.prototype.init=function(){
		//console.log("init");
		var self=this;
		var template=$("tbody tr.template",this.selector)
		template=$(template).clone();
		template.removeClass("template");
		this.template=template
		//console.log(this.selector);
		$("tbody tr.template",this.selector).remove();
		
		$("input",this.selector).bind("change",function(event){
			 self.inputChangeHandler(event)
	    });
		$("input",this.selector).bind("dblclick",function(event){
			 self.inputDblclickHandler(event)
	    });
		$(".button",this.selector).bind("click",function(event){
			 self.buttonClickHandler(event)
	    });
		/*if($("tbody tr",this.selector).length==0){
			this.addRow();
		}*/
		this.update();
	}
	EditableTable.prototype.removeAll=function(){
		$("tbody tr",this.selector).remove();
	}
	EditableTable.prototype.removeByIndex=function(index){
		$("tbody tr",this.selector).eq(index).remove();
	}
	EditableTable.prototype.inputChangeHandler=function(event){
		this.update();
	}
	EditableTable.prototype.inputDblclickHandler=function(event){
		
	}
	EditableTable.prototype.getLength=function(){
		console.log($(this.selector+" tbody tr"));
		
		var length=$(this.selector+" tbody tr").length;
		return length;
	}
	EditableTable.prototype.buttonClickHandler=function(event){
		var target=event.currentTarget;
		var row=$(target).parent().parent();
		var col=$(target).parent();
		
		var className=$(col).get(0).className;
		console.log(className);
		if(className=="delete"){
			$(row).remove();
			this.update();
		}
		if(className=="up"){
			var prevRows = $(row).prev();
	        if(prevRows.length != 0){
	        	prevRows.before(row);
	        }
			this.update()
		}
		if(className=="down"){
			var nextRows = $(row).next();
	        if(nextRows.length != 0){
	        	nextRows.after(row);
	        }
			this.update()
		}
		return name;
	}
	EditableTable.prototype.keydownHandler=function(event){
		return true;
	}
	EditableTable.prototype.keyupHandler=function(event){
		this.update();
		return true;
	}
	
	EditableTable.prototype.validateInteger=function(event){
		var keyCode=event.keyCode;
		//console.log(keyCode);
		if(keyCode==8 || keyCode ==46){
			return true;
		}
		if(keyCode>=37 && keyCode<=40){
			return true;
		}
		var key=event.key;
		var regExp=new RegExp("[0-9]");
		if(regExp.test(key)){
			return true;
		}else{
			return false;
		}
	}
	EditableTable.prototype.validateFloat=function(event){
		var keyCode=event.keyCode;
		//console.log(keyCode);
		if(keyCode==8 || keyCode ==46){
			return true;
		}
		if(keyCode>=37 && keyCode<=40){
			return true;
		}
		var key=event.key;
		var regExp=new RegExp("[0-9\.]");
		if(regExp.test(key)){
			return true;
		}else{
			return false;
		}
	}
	EditableTable.prototype.getDataList=function(){
		var dataList=new Array();
		var data={};
		var self=this;
		var evalStr="";
		
		$("tbody tr",this.selector).each(function(index, element) {
			var children=$(element).children();
			var cell=null;
			var name="";
			data={};
			for(var i=0;i<children.length;i++){
				cell=children[i]
				var name=$(cell).attr("name");
				var value=$(cell).text();
				evalStr="data."+name+"=value";
				eval(evalStr);
			}
			dataList.push(data);
		});
		return dataList;
	}
	EditableTable.prototype.getDataListValue=function(){
		var dataListValue="";
		var dataValue="";
		var value="";
		
		var temp="";
		var m=0;
		$("tbody tr",this.selector).each(function(index, element) {
			var children=$(element).children();
			var cell=null;
			var name="";
			dataValue=",{";
			for(var i=0;i<children.length;i++){
				cell=children[i]
				var name=$(cell).attr("name");
				var value=$(cell).text();
				dataValue+="\""+name+"\":\""+value+"\"";
				if(i<children.length-1){
					dataValue+=",";
				}
			}
			dataValue+="}";
			dataListValue+=dataValue;
		});
		if(dataListValue!=""){
			dataListValue=dataListValue.substr(1);
		}
		dataListValue="["+dataListValue+"]";
		return dataListValue;
	}
	EditableTable.prototype.getValueByName=function(context,name){
		//console.log($("[name='"+name+"']",context).eq(0));
		var value=$("[name='"+name+"']",context).eq(0).text();
		return value;
	}
	EditableTable.prototype.addRow=function(item){
		
		var self=this;
		var row=$(this.template).clone();
		ht.update(row);
		$("tbody",this.selector).append(row);
		
		
		$("input",row).bind("change",function(event){
			 self.inputChangeHandler(event)
	    });
		$("input",row).bind("dblclick",function(event){
			 self.inputDblclickHandler(event)
	    });
		$(".button",row).bind("click",function(event){
			 self.buttonClickHandler(event)
	    });
		if(typeof item != "undefined"){
			console.log(item);
			for (var key in item)  {
				var value=item[key];
				//console.log(value);
				$("[name=parent_"+key+"]",row).val(value);
				$("[name=item_"+key+"]",row).val(value);
			}
		}
		
		this.update();
	}
	EditableTable.prototype.clearRowList=function(){
	}
	EditableTable.prototype.addRowList=function(itemList){
		this.clearRowList();
		for(var i in itemList){
			this.addRow(itemList[i]);
		}
		//this.addRow();
		this.update();
	}
	EditableTable.prototype.setValue=function(index,selector,value){
		//$("tbody tr",this.selector).eq(index).find(selector).eq(0).text(value)
		$("tbody tr",this.selector).eq(index).find(selector).eq(0).val(value)
		$("tbody tr",this.selector).eq(index).find(selector).eq(0).change();
	}
	EditableTable.prototype.getValue=function(index,selector){
		var value=$("tbody tr",this.selector).eq(index).find(selector).eq(0).val()
		return value;
	}
	EditableTable.prototype.getRowIndexByCell=function(cell){
		var index=$(cell).parent().parent().find("tr").index($(cell).parent());
		return index;
	}
	EditableTable.prototype.getRowIndex=function(object){
		var row=$(object).parent().parent();
		var index=$(row).parent().find("tr").index(row);
		return index;
	}
	/*EditableTable.prototype.cellClickHandler=function(event){
		var target=event.currentTarget;
		var index=this.getRowIndexByCell(target);
		
		var name=$(target).attr("name");
		console.log(name)
		
		//选择联系人
		/*if(name=="name" || name=="code"){
			selectContact(index);
		}*/
	//}
	
	//更新
	EditableTable.prototype.update=function(){
	}
	HTMLTurbo.control.EditableTable=EditableTable;